package com.imooc.girl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class GirlController {

    @Autowired
    private GrilRespository girlRespository;

    @Autowired
    private GirlService girlService;

    /*
    查询女生列表
     */
    @GetMapping(value = "/girls")
    public List<Girl> girlList(){

        return girlRespository.findAll();

    }

    @PostMapping(value = "/girls")
    public Girl girlAdd(@RequestParam("BroadSize") String BroadSize,
                        @RequestParam("Age") Integer Age){

        System.out.println("cup:" + BroadSize + ", age:"+Age);
        Girl girl = new Girl();
        girl.setAge(Age);
        girl.setBroadSize(BroadSize);
        return girlRespository.save(girl);

    }

    /*
    查询一个女生
     */
    @GetMapping(value = "/girls/{id}")
    public Girl girlFindOne(@PathVariable("id") Integer id){
        return girlRespository.findOne(id);
    }

    /*
    更新一个女人的信息
     */
    @PutMapping(value = "/girls/{id}")
    public Girl girlUpdate(@PathVariable("id") Integer id,
                           @RequestParam("BroadSize") String BroadSize,
                           @RequestParam("Age") Integer Age){
        Girl girl = new Girl();
        girl.setId(id);
        girl.setAge(Age);
//        girl.setBroadSize(BroadSize);
        return girlRespository.save(girl);
    }

    /*
    删除一个女人的信息
     */
    @DeleteMapping(value = "/girls/{id}")
    public void girlDelete(@PathVariable("id") Integer id){
        girlRespository.delete(id);
    }

//    /*
//    通过年龄查询女生列表
//     */
//    @GetMapping(value = "/girls/{Age}")
//    public List<Girl> girlListByAge(@PathVariable("Age") Integer Age){
//        return girlRespository.findByAge(Age);
//    }

    @PostMapping(value = "/girls/two")
    public void girlTwo(){
        girlService.insertTwo();
    }


}
